<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>

            .u_star {
                padding: 0.8rem 0;
                margin-top: 2rem;
                display: block;
                zoom: 1;
            }
            
            .u_star span {
                display: inline-block;
                width: 1.8rem;
                height: 1.72rem;
                background: url("./img/star.jpg") -2px -72px no-repeat;
                background-size: 1.8rem auto;
                margin-right: 3%;
            }
            
            .u_star span.on {
                background: url("./img/star.jpg") -2px -1px no-repeat;
                background-size: 1.8rem auto;
            }
   
    </style>
</head>
<body>
    <div class="u_star">
        <span></span>
        <span></span>
        <span></span>
        <span></span>
        <span></span>
    </div>
    <script src="js/jquery-3.6.0.js"></script>
    <script>
        $(function() {
            var star = $('.u_star span');
            star.on('click', function() {
                var len = $(this).index();
                star.each(function(i, e) {
                    if(i <= len) {
                        $(this).addClass('on');
                    } else {
                        $(this).removeClass('on');
                    }
                })

            });

        })
    </script>
</body>
</html>